package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrdersService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrdersSearchVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "订单管理端相关接口")
@RequestMapping("/admin/order")
public class OrdersAdminController {
    @Autowired
    private OrdersService ordersService;

    /**
     * 管理端查询订单
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("管理端查询订单接口")
    public Result<PageResult> search(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = ordersService.search(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 查询订单状态数量
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("查询订单状态数量接口")
    public Result<OrderStatisticsVO> statistics(){
        OrderStatisticsVO orderStatisticsVO = ordersService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 管理端取消订单
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("管理端取消订单接口")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        ordersService.adminCancel(ordersCancelDTO);
        return Result.success();
    }

    @PutMapping("/rejection")
    @ApiOperation("管理端拒绝订单接口")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        ordersService.rejection(ordersRejectionDTO);
        return Result.success();
    }
    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation("管理端查询订单详情接口")
    public Result<OrdersSearchVO> details(@PathVariable Long id){
        OrdersSearchVO ordersSearchVO = ordersService.details(id);
        return Result.success(ordersSearchVO);
    }

    /**
     * 管理端接单
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/confirm")
    @ApiOperation("管理端接单接口")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        ordersService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 管理端派送订单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("管理端派送订单接口")
    public Result delivery(@PathVariable Long id){
        ordersService.delivery(id);
        return Result.success();
    }

    /**
     * 管理端完成订单
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("管理端完成订单接口")
    public Result complete(@PathVariable Long id){
        ordersService.complete(id);
        return Result.success();
    }
}
